-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix floating point error in bezier bounding box calculation #219
base: master
Are you sure you want to change the base?
Fix floating point error in bezier bounding box calculation #219
Conversation
Hey, @mathandy, could you have a look at this when you have time? Thanks! |
I found this error as well.
|
Hey @Brishen, thanks for the suggestion! |
@bouhek I think I got my conditions slightly wrong. It should probably be
|
Description
During my recent work with this library, I encountered an issue related to the calculation of bounding boxes for certain cubic Bezier curves. This problem appeared to stem from a floating point error that occurs during the computation of the denominator, which then affects subsequent conditions.
To resolve this, I have implemented a solution in this PR: the introduction of a
FLOAT_EPSILON
constant. This constant serves as a threshold for acceptable error in floating point calculations, effectively addressing the issue at hand.To demonstrate the efficacy of this fix, I've added the zero_denominator_bezier_curve test. Included below are before-and-after images to illustrate the improvement. In these images, the Bezier curve is depicted by a black line, while the red rectangle represents the bounding box as calculated. This visual comparison clearly shows the enhancement brought about by this PR.
Before the fix
After the fix
Other test cases added
Test start_end_bbox_bezier_curve
Test general_bezier_curve